/*
 *  Copyright (c) 2025 Huawei Device Co., Ltd.
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

import 'package:flutter/material.dart';
import 'package:hadss_geometry_transition/hadss_geometry_transition.dart';

class HomeScreen extends StatefulWidget {
  const HomeScreen({super.key});

  @override
  State<HomeScreen> createState() => _HomeScreenState();
}

class _HomeScreenState extends State<HomeScreen> {
  @override
  Widget build(BuildContext context) {
    final double screenRadius = MediaQuery.of(context).padding.top - 10;
    return Scaffold(
      body: Align(
        alignment: Alignment.center,
        child: GeometryTransition(
          closedRadius: const BorderRadius.all(Radius.circular(8.0)),
          openRadius: BorderRadius.all(Radius.circular(screenRadius)),
          closedBuilder: (context, open) {
            return SizedBox(
                width: 100,
                height: 100,
                // 初始化圆角
                child: ClipRRect(
                    borderRadius: const BorderRadius.all(Radius.circular(8.0)),
                    child: Stack(
                      alignment: Alignment.center,
                      children: [
                        Container(
                          width: 100,
                          height: 100,
                          color: Colors.orange,
                        ),
                        const SizedBox(height: 20),
                        Align(
                          alignment: Alignment.center,
                          child: FittedBox(
                              fit: BoxFit.contain,
                              child: ElevatedButton(
                                onPressed: open,
                                child: const Text('跳转'),
                              )),
                        )
                      ],
                    )));
          },
          openBuilder: (context, close) {
            return Scaffold(
              backgroundColor: Colors.blue,
              body: Align(
                alignment: Alignment.topCenter,
                child: Container(
                  width: 200,
                  height: 200,
                  alignment: Alignment.topCenter,
                  color: Colors.red,
                ),
              ),
            );
          },
          tappable: true,
          onPushCallback: (data) => debugPrint('动画回调'),
        ),
      ),
    );
  }
}
